package com.example.hms.awareness;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

import com.huawei.hms.kit.awareness.barrier.BarrierStatus;

public class LightBarrierReceiver extends BroadcastReceiver {
    
    private static final String TAG = LightBarrierReceiver.class.getSimpleName();
    
    @Override
    public void onReceive(Context context, Intent intent) {
        BarrierStatus barrierStatus = BarrierStatus.extract(intent);
        String label = barrierStatus.getBarrierLabel();
        switch (barrierStatus.getPresentStatus()) {
            case BarrierStatus.TRUE:
                Log.i(TAG, label + " status:true");
                if (SensorUtil.isFaceDown) {
                    // Intent intentone = new Intent(context.getApplicationContext(), QRActivity.class);
                    // intentone.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    // context.startActivity(intentone);
                    try {
                        // open ALiPay QR code
                        Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=xxxx");
                        Intent intent0 = new Intent(Intent.ACTION_VIEW, uri);
                        context.startActivity(intent0);
                    } catch (Exception e) {

                    }
                }
                break;
            case BarrierStatus.FALSE:
                Log.i(TAG, label + " status:false");
                break;
            case BarrierStatus.UNKNOWN:
                Log.i(TAG, label + " status:unknown");
                break;
        }
    }
}
